package com.mad.bakergps;

import java.util.ArrayList;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class XMLHandler extends DefaultHandler {
	
	public ArrayList<Building> Buildings= new ArrayList<Building>();
	private Building currentBuilding= new Building();
	
	
	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		if(localName.equals("Building"))
		{
			currentBuilding = new Building();
			currentBuilding.setName(attributes.getValue("name"));
			currentBuilding.setNumber(Integer.parseInt(attributes.getValue("number")));
		}
		else if(localName.equals("Room"))
		{
			Room temp=new Room();
			temp.setName(attributes.getValue("name"));
			if(attributes.getValue("number")!=null)
				temp.setNumber(Integer.parseInt(attributes.getValue("number")));
			currentBuilding.addRoom(temp);
		}
		
	}
	
	
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		
		if(localName.equals("Building"))
		{
			Buildings.add(currentBuilding);
		}	
	}

}
